<template>
	<uv-popup ref="popupRef" closeable mode="bottom" round="28rpx">
		<view class="person-info">
			<view class="title">紧急联系人</view>
			<view class="form">
				<view class="form-item">
					<view class="label">联系人</view>
					<view class="value">
						<input v-model="queryForm.emergencyName" :cursor-spacing="cursorSpacing" type="text"
							placeholder="请输入姓名">
					</view>
				</view>
				<view class="form-item">
					<view class="label">手机号</view>
					<view class="value">
						<input v-model="queryForm.emergencyPhone" :cursor-spacing="cursorSpacing" type="text"
							placeholder="请输入手机号">
					</view>
				</view>
				<view class="form-item">
					<view class="label">关系</view>
					<view class="value">
						<input v-model="queryForm.emergencyRelation" :cursor-spacing="cursorSpacing" type="text"
							placeholder="请输入关系">
					</view>
				</view>
			</view>
			<view class="submit">
				<button class="cu-btn" @click="handSubmit">确定</button>
			</view>
		</view>
	</uv-popup>
</template>

<script setup>
	import {
		reactive,
		ref,
		defineEmits
	} from 'vue'

	const emit = defineEmits(['change'])

	const rpxToPx = (rpx) => {
		const screenWidth = uni.getSystemInfoSync().screenWidth
		return (screenWidth * Number.parseInt(rpx)) / 750
	}
	const cursorSpacing = rpxToPx(30)

	const queryForm = ref({})

	const handSubmit = () => {
		const params = queryForm.value
		if (!params.emergencyName) {
			uni.$uv.toast('请输入姓名')
			return
		}
		if (!params.emergencyPhone) {
			uni.$uv.toast('请输入手机号')
			return
		}
		if (!uni.$uv.test.mobile(params.emergencyPhone)) {
			uni.$uv.toast('手机号格式不正确')
			return
		}
		if (!params.emergencyRelation) {
			uni.$uv.toast('请输入关系')
			return
		}
		emit('change', params)
		handClose()
	}


	const popupRef = ref(null)
	const handOpen = (row) => {
		queryForm.value = row
		popupRef.value.open()
	}
	const handClose = () => {
		popupRef.value.close()
	}
	defineExpose({
		handOpen
	})
</script>

<style lang="scss" scoped>
	.person-info {
		padding: 24rpx;
		padding-bottom: 58rpx;
		padding-bottom: calc(constant(safe-area-inset-bottom) + 58rpx);
		padding-bottom: calc(env(safe-area-inset-bottom) + 58rpx);

		.title {
			text-align: center;
			font-size: 36rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #333333;
		}

		.form {
			margin-top: 64rpx;

			&-item {
				display: flex;
				align-items: center;
				border-bottom: 1rpx solid #EEEEEE;
				padding: 30rpx 0;

				&:last-child {
					border: none;
				}

				.label {
					font-size: 30rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
				}

				.value {
					flex: 1;
					margin-left: 20rpx;
					display: flex;
					justify-content: flex-end;

					input {
						flex: 1;
						text-align: right;
					}
				}

				.photo {
					margin-left: 36rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;

					image {
						width: 44rpx;
						height: 44rpx;
					}

					text {
						margin-top: 4rpx;
						font-size: 22rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #333333;
					}
				}

				.uploads {
					display: flex;
					margin-top: 26rpx;

					image {
						width: 292rpx;
						height: 184rpx;
					}
				}
			}
		}

		.submit {
			margin-top: 22rpx;
			position: relative;
			z-index: 3;

			.cu-btn {
				width: 702rpx;
				height: 100rpx;
				background: #FFC434;
				border-radius: 16rpx;
				font-size: 32rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #333333;
			}
		}
	}
</style>